calculate Fit Dp
EN Shared pure-math scaling kernel used by toDynamicFitPx and toDynamicFitDp.
Algorithm summary:
Applies Inverter rules to swap the effective DpQualifier based on screen orientation.
If ignoreMultiWindows is
true, detects split-screen mode via layout flags; if active, returns baseValue unchanged so the UI does not over-scale inside a small window.For the common path (
SMALL_WIDTH+DEFAULTinverter + no custom sensitivity), delegates to DimenCache.calculateRawScaling which reads pre-computed factors from DimenCache.ScreenFactors — a single float multiply, zero extra allocations.For other qualifiers or a custom sensitivity constant, reads the screen dimension from android.content.res.Configuration and performs the scaling formula inline.
Performance: Simple paths without Aspect Ratio complete in ~2 ns (single multiply). Paths with Aspect Ratio require ~41 ns on Snapdragon 888 (includes ln() fallback). Results are memoized by the DimenCache shared across code and compose packages.
Note: Both
code/andcompose/packages intentionally maintain separate copies of this function because thecode/variant operates on android.content.res.Configuration directly (no Compose runtime), whilecompose/reads it from androidx.compose.ui.platform.LocalConfiguration. The math is identical; only the Context acquisition path differs.
PT Núcleo de escalonamento puro compartilhado por toDynamicFitPx e toDynamicFitDp.
Resumo do algoritmo:
Aplica as regras de Inverter para trocar o DpQualifier efetivo conforme a orientação.
Se ignoreMultiWindows for
true, detecta split-screen via flags de layout; se ativo, retorna baseValue sem escalar.Para o caminho comum (SMALL_WIDTH + DEFAULT + sem sensibilidade customizada), delega para DimenCache.calculateRawScaling com os fatores pré-calculados.
Para outros qualificadores ou sensibilidade customizada, lê a dimensão da tela da android.content.res.Configuration e executa a fórmula de escalonamento inline.
Nota: Os pacotes
code/ecompose/mantêm cópias separadas intencionalmente. A versãocode/opera sobre android.content.res.Configuration diretamente, enquanto a versãocompose/usa androidx.compose.ui.platform.LocalConfiguration. A matemática é idêntica; apenas a obtenção do contexto difere.
Return
Scaled Dp value as a raw Float.
Parameters
Raw Dp value to scale (e.g. 16f for 16 dp).
Current android.content.res.Configuration from the context.
Original screen qualifier before inversion.
Orientation-swap rule.
Whether to suppress scaling in multi-window mode.
Whether to apply the AR multiplier.
Custom AR sensitivity constant, or null for the library default.